package com.lanou.zy.projecta.activity;

import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.lanou.zy.projecta.R;
import com.lanou.zy.projecta.adapter.RoundWorldViewPagerAdapter;
import com.lanou.zy.projecta.fragment.LatestFragment;
import com.lanou.zy.projecta.fragment.NotesFragment;
import com.lanou.zy.projecta.fragment.QuestionFragment;
import com.lanou.zy.projecta.fragment.RenderFragment;
import com.lanou.zy.projecta.fragment.TogetherFragment;
import com.lanou.zy.projecta.util.DataChange;
import com.lanou.zy.projecta.util.GetVolleyDatas;
import com.lanou.zy.projecta.util.StringUtil;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by dllo on 15/11/3.
 */
public class RoundWorldActivity extends FragmentActivity implements View.OnClickListener {
    private TabLayout roundWorldTabLayout;
    private ViewPager viewPager;
    private ImageView backToCommunity_TV, roundWorldHead_Iv;
    private TextView foreverRun_Tv, titleRv_Tv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_round_world);
        initView();
        initData();
    }

    private void initView() {
        backToCommunity_TV = (ImageView) findViewById(R.id.backToCommunity_TV);
        backToCommunity_TV.setOnClickListener(this);
        roundWorldTabLayout = (TabLayout) findViewById(R.id.roundWorldTabLayout);
        viewPager = (ViewPager) findViewById(R.id.roundWorldViewPager);
        roundWorldTabLayout.setTabMode(roundWorldTabLayout.MODE_SCROLLABLE);
        roundWorldTabLayout.setTabTextColors(R.color.tabFirst, R.color.tabSecond);
        roundWorldTabLayout.setSelectedTabIndicatorColor(getResources().getColor(R.color.tabSecond));

        roundWorldHead_Iv = (ImageView) findViewById(R.id.roundWorldHead_Iv);
        foreverRun_Tv = (TextView) findViewById(R.id.foreverRun_Tv);
        titleRv_Tv = (TextView) findViewById(R.id.titleRv_Tv);

    }

    // 添加新的页卡
    private void initData() {
        Intent intent = getIntent();
        String id = intent.getStringExtra("id");
        String photo = intent.getStringExtra("photo");
        String title = intent.getStringExtra("title");
        String content = intent.getStringExtra("content");
        titleRv_Tv.setText(title);
        foreverRun_Tv.setText(content + "个帖子");
        GetVolleyDatas.getBitmapRequest(photo, roundWorldHead_Iv);

        List<String> tabList = new ArrayList<>();
        List<Fragment> fragmentList = new ArrayList<>();

        fragmentList.add(LatestFragment.newInstance(id));
        fragmentList.add(NotesFragment.newInstance(id));
        fragmentList.add(new TogetherFragment());
        fragmentList.add(new QuestionFragment());
        fragmentList.add(new RenderFragment());

        tabList.add("最新");
        tabList.add("攻略");
        tabList.add("结伴");
        tabList.add("问答");
        tabList.add("转让");

        RoundWorldViewPagerAdapter roundWorldViewPager = new RoundWorldViewPagerAdapter(getSupportFragmentManager(), fragmentList, tabList);
        viewPager.setAdapter(roundWorldViewPager);
        roundWorldTabLayout.setupWithViewPager(viewPager);
        roundWorldTabLayout.setTabsFromPagerAdapter(roundWorldViewPager);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.backToCommunity_TV:
                onBackPressed();
                break;
        }
    }
}
